import matplotlib.pyplot as plt
plt.rcParams['font.sans-serif'] = ['SimHei']
plt.rcParams['axes.unicode_minus'] = False

#创建图形和子图
fig, axes = plt.subplots(2, 3, figsize=(18, 8), dpi=100)
fig.patch.set_facecolor('#2C3E50')

#年龄环形图
ax = axes[0, 0]
labels = ['18-24', '25-29', '30-34', '35-39', '40=以上']
sizes = [7, 16, 22, 20, 35]
colors = ['#5DADE2', '#F39C12', '#2ECC71', '#F4D03F', '#2874A6']
wedges, texts, autotexts = ax.pie(
    sizes, labels=None, colors=colors, autopct='%1.0f%%', startangle=90, pctdistance=0.75
)
centre_circle = plt.Circle((0, 0), 0.60, fc='#2C3E50')
ax.add_artist(centre_circle)
ax.set_title('年龄', fontsize=16, color='white', pad=10)
ax.set_facecolor('#2C3E50')
for autotext in autotexts:
    autotext.set_color('white')

legend = ax.legend(
    wedges, labels, loc="center left", bbox_to_anchor=(1, 0, 0.5, 1), fontsize=10
)
legend.get_frame().set_facecolor('#2C3E50')
legend.get_frame().set_edgecolor('white')
plt.setp(legend.get_texts(), color='white')

#性别环形图
ax = axes[0, 1]
labels = ['男', '女']
sizes = [60, 40]
colors = ['#F39C12', '#5DADE2']
wedges, texts, autotexts = ax.pie(
    sizes, labels=None, colors=colors, autopct='%1.0f%%', startangle=90, pctdistance=0.75
)
centre_circle = plt.Circle((0, 0), 0.60, fc='#2C3E50')
ax.add_artist(centre_circle)
ax.set_title('性别', fontsize=16, color='white', pad=10)
ax.set_facecolor('#2C3E50')
for autotext in autotexts:
    autotext.set_color('white')

legend = ax.legend(
    wedges, labels, loc="center left", bbox_to_anchor=(1, 0, 0.5, 1), fontsize=10
)
legend.get_frame().set_facecolor('#2C3E50')
legend.get_frame().set_edgecolor('white')
plt.setp(legend.get_texts(), color='white')

#婚姻状况环形图
ax = axes[0, 2]
labels = ['单身', '已婚', '离异']
sizes = [32, 46, 22]
colors = ['#F39C12', '#2874A6', '#5DADE2']
wedges, texts, autotexts = ax.pie(
    sizes, labels=None, colors=colors, autopct='%1.0f%%', startangle=90, pctdistance=0.75
)
centre_circle = plt.Circle((0, 0), 0.60, fc='#2C3E50')
ax.add_artist(centre_circle)
ax.set_title('婚姻状况', fontsize=16, color='white', pad=10)
ax.set_facecolor('#2C3E50')
for autotext in autotexts:
    autotext.set_color('white')

legend = ax.legend(
    wedges, labels, loc="center left", bbox_to_anchor=(1, 0, 0.5, 1), fontsize=10
)
legend.get_frame().set_facecolor('#2C3E50')
legend.get_frame().set_edgecolor('white')
plt.setp(legend.get_texts(), color='white')

#学历
ax = axes[1, 0]
labels = ['博士研究生', '硕士研究生', '本科', '专科', '专科以下']
values = [48, 398, 572, 170, 282]
bars = ax.barh(labels, values, color='#5DADE2')
ax.set_title('学历', fontsize=16, color='white', pad=10)
ax.tick_params(axis='y', colors='white')
ax.xaxis.set_visible(False)
for bar in bars:
    ax.text(bar.get_width() + 5, bar.get_y() + bar.get_height() / 2, f'{int(bar.get_width())}', va='center', color='white')
ax.set_facecolor('#2C3E50')

#入转调
ax = axes[1, 1]
labels = ['入职', '转入', '转出']
values = [40, 5, 5]
bars = ax.bar(labels, values, color='#5DADE2', width=0.5)
ax.text(1, max(values) + 10, '总人数: 147', fontsize=14, color='white', ha='center')
ax.set_title('入转调', fontsize=16, color='white', pad=10)
ax.tick_params(axis='x', colors='white')
ax.tick_params(axis='y', left=False, labelleft=False)
ax.set_facecolor('#2C3E50')
for bar in bars:
    ax.text(bar.get_x() + bar.get_width() / 2, bar.get_height() + 1, f'{int(bar.get_height())}', ha='center', color='white')

#部门
ax = axes[1, 2]
labels = ['财务部', '人力资源部', '行政部', '信息技术部', '研发部', '销售部']
values = [17, 46, 9, 162, 799, 437]
bars = ax.barh(labels, values, color='#5DADE2')
ax.set_title('部门', fontsize=16, color='white', pad=10)
ax.tick_params(axis='y', colors='white')
ax.tick_params(axis='x', length=0, labelbottom=False)
ax.invert_yaxis()
ax.set_facecolor('#2C3E50')
for bar in bars:
    ax.text(bar.get_width() + 10, bar.get_y() + bar.get_height() / 2, f'{int(bar.get_width())}', va='center', color='white')

plt.suptitle('公司人员结构看板', fontsize=20, color='white', y=0.95)
plt.tight_layout(rect=[0, 0, 1, 0.95])
plt.savefig('D:/python charm/01/可视化/人力资源静态数据大屏设计/图片.png', dpi=300, bbox_inches='tight')
plt.show()